

function result(row,col) {
  let count = 1
  const arr = new Array(row).fill(0).map(() => new Array(col).fill(0));
  let i = 0,j=0;
  let stepi = 0,stepj=1;
  function isblock() {
    if(!arr[i + stepi] || arr[i + stepi][j + stepj]!==0) {
        return true
    } 
  }

  while(true) {
    arr[i][j] = count++
    if(isblock()) {
        if(stepi==0) {
            stepi = stepj
            stepj = 0
        } else {
            stepj = -stepi
            stepi = 0
        }
        if(isblock()) {
            break
        }
    }
    i+=stepi
    j+=stepj
  }
  return arr;
}



console.log(JSON.stringify(result(3,4),null,0))